package com.example.demo.service;

import com.example.demo.bean.SearchUserNumberByCondition;
import com.example.demo.bean.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username) {
        return userMapper.selectUserByUserName(username);
    }

    @Override
    public void addUser(User user){
        BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
        user.setPassword(encoder.encode(user.getPassword()));
        userMapper.addUser(user) ;
    }

    @Override
    public List<User> getAllUser(){
        return userMapper.getAllUser();
    }

    @Override
    public List<User> getAllComUser() {
        return userMapper.getAllComUser();
    }

    @Override
    public void updateUserStatus1(Integer id) {
        userMapper.updateUserStatus1(id);
    }

    @Override
    public void updateUserStatus2(Integer id) {
        userMapper.updateUserStatus2(id);
    }

    @Override
    public void deleteUser(Integer id) {
        userMapper.deleteUser(id);
    }

    @Override
    public List<User> findUserByUserId(User user) {
        return userMapper.selectUserByUserId(user.getUid());
    }

    @Override
    public List<User> selectUserByCondition(SearchUserNumberByCondition searchUserNumberByCondition) {
        return userMapper.selectUserByCondition(searchUserNumberByCondition);
    }

    @Override
    public List<User> getAllAdmin() {
        return userMapper.getAllAdmin();
    }

}
